package com.example.seven.mynews.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * 外部类实现适配器
 */
public class ViewPagerAdapter extends PagerAdapter{

    private List<View> views;
    public ViewPagerAdapter(List<View> views){
        this.views = views;
    }

    @Override
    public int getCount() {
        //得到布局数
        return views.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        //销毁
        container.removeView(views.get(position));
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        //实例化
        container.addView(views.get(position));
        return views.get(position);
    }
}
